package com.yunhai.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.dto.Ret;
import com.yunhai.device.service.DevicePreloadService;
import com.yunhai.model.entity.dms.DmsDevicePreloadEntity;
import com.yunhai.model.vo.dms.DmsDevicePreloadQuery;
import com.yunhai.model.vo.dms.DmsDevicePreloadVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/devicePreload")
public class DevicePreloadController {

	@Resource
	private DevicePreloadService devicePreloadService;


	/**
	 * 获取 DevicePreload 分页列表
	 */
	@GetMapping("/pagination")
	public Ret getDevicePreloadPagination(PaginationVo paginationVo, DmsDevicePreloadQuery dmsDevicePreloadQuery ) throws Exception {
		IPage page = devicePreloadService.getDevicePreloadPagination(paginationVo, dmsDevicePreloadQuery );
		return Ret.toPage(page);
	}

	/**
	 * 获取 DevicePreload 所有数据
	 */
	@GetMapping("/allList")
	public Ret getDevicePreloadAllList( DmsDevicePreloadQuery dmsDevicePreloadQuery ) throws Exception {
		List<DmsDevicePreloadEntity> list = devicePreloadService.getDevicePreloadAllList( dmsDevicePreloadQuery );
		return Ret.ok(list);
	}


	/**
	 * 获取 DevicePreload 详情
	 */
	@GetMapping("/{id}")
	public Ret getDevicePreloadDetailById(@PathVariable Long id) throws Exception {

	    DmsDevicePreloadEntity dmsDevicePreloadEntity = devicePreloadService.getDevicePreloadDetail(id);
		return Ret.ok(dmsDevicePreloadEntity);
	}

	/**
	 * 根据 门店id 获取对应的部署码
	 * */
	@PostMapping("/storeId")
	public Ret devicePreloadService( @RequestBody List<Long> storeIds ) throws Exception {

  		List<DmsDevicePreloadEntity> list
				= devicePreloadService.getDevicePreloadDetailByStoreIds(storeIds);
		return Ret.ok(list);
	}


	/**
	 * 新增 DevicePreload
	 * */
	@PostMapping("")
	public Ret addDevicePreload(@RequestBody DmsDevicePreloadVo dmsDevicePreloadVo) throws Exception {

		devicePreloadService.addDevicePreload(dmsDevicePreloadVo);
		return Ret.ok();
	}


	/**
	 * 更新 DevicePreload
	 * */
	@PutMapping("")
	public Ret updateDevicePreload(@RequestBody DmsDevicePreloadVo dmsDevicePreloadVo) throws Exception {

		devicePreloadService.updateDevicePreload(dmsDevicePreloadVo);
		return Ret.ok();
	}


	/**
	 * 删除 DevicePreload
	 * */
	@PostMapping("/batchRemove")
	public Ret batchRemoveDevicePreload( @RequestBody List<Long> ids ) throws Exception {

	    devicePreloadService.batchRemoveDevicePreload(ids);
		return Ret.ok();
	}
}
